|
|
|
|
|
|
|
Figure 12.20
Rotating the point (x, y) until it lies on the X axis. |
|
|
|
|
|
|
|
|
Using this fact, you can write a Visual Basic routine that initializes a transformation matrix to rotate a point until it lies in the X axis without calling the relatively slow Sin and Cos functions. |
|
|
|
 |
|
|
|
|
' Create a rotation matrix that rotates the point
' (x, y) onto the X axis. Public Sub m2RotateIntoX(Result() As Single, _
ByVal x As Single, ByVal y As Single)
Dim d As Single
m2Identity Result
d = Sqr(x * x + y *y)
Result(1, 1) = x / d
Result(1, 2) = -y / d
Result(2, 1) = -Result(1, 2)
Result(2, 2) = Result(1, 1)
End Sub |
|
|
|
|
|
|
|
|
With these routines as tools, you can build more complicated combinations of transformations. The following routines use these tools to create transformation matrices for scaling around a point other than the origin, reflection around an arbitrary line, and rotation around a specified point. |
|
|
|
 |
|
|
|
|
' Create a scaling matrix for scaling by factors
' of sx and sy at the point (x, y). Public Sub m2ScaleAt(Result() As Single, _
ByVal sx As Single, ByVal sy As Single, _
ByVal x As Single, ByVal y As Single)
Dim T(1 To 3, 1 To 3) As Single
Dim S(1 To 3, 1 To 3) As Single
Dim T_Inv(1 To 3, 1 To 3) As Single
Dim M(1 To 3, 1 To 3) As Single |
|
|
|
|
|